from textwrap import dedent

from agno.agent import Agent
from agno.models.deepseek import DeepSeek
from agno.team.team import Team
from agno.tools.duckduckgo import DuckDuckGoTools
from agno.tools.reasoning import ReasoningTools
from agno.tools.yfinance import YFinanceTools

# 分别构建两个代理，一个用于处理网络搜索请求，另一个用于处理财务数据请求。
web_agent = Agent(
    name="Web Search Agent",
    role="Handle web search requests",
    model=DeepSeek(id="deepseek-chat"),
    tools=[DuckDuckGoTools()],
    instructions="Always include sources.",
    add_datetime_to_instructions=True,
    monitoring=True,
)

finance_agent = Agent(
    name="Finance Agent",
    role="Handle financial data requests",
    model=DeepSeek(id="deepseek-chat"),
    tools=[
        YFinanceTools(stock_price=True, analyst_recommendations=True, company_info=True)
    ],
    instructions="Use tables to display data.",
    add_datetime_to_instructions=True,
    monitoring=True,
)

# 构建一个团队leader角色，该团队由两个代理组成，并使用推理工具来处理任务。
team_leader = Team(
    name="Reasoning Finance Team Leader",
    mode="coordinate",
    model=DeepSeek(id="deepseek-chat"),
    members=[web_agent, finance_agent],
    tools=[ReasoningTools(add_instructions=True)],
    instructions=[
        "根据用户提出的任务，判断并使用相应代理工具",
        "Use tables to display data.",
        "Only respond with the final answer, no other text.",
    ],
    markdown=True,
    show_members_responses=True,
    enable_agentic_context=True,
    add_datetime_to_instructions=True,
    success_criteria="The team has successfully completed the task.",
    monitoring=True,
)

task = """\
Analyze the semiconductor market performance focusing on:
- NVIDIA (NVDA)
- AMD (AMD)
- Intel (INTC)
- Taiwan Semiconductor (TSM)
Compare their market positions, growth metrics, and future outlook."""

team_leader.print_response(
    task,
    stream=True,
    stream_intermediate_steps=True,
    show_full_reasoning=True,
)
